
import time
import pytest
from dingTalk.send import Send_DingTalk

@pytest.fixture(scope="module", autouse=True)
def func(request):
    pass

sd = Send_DingTalk()

def pytest_terminal_summary(terminalreporter, exitstatus, config):
    total = terminalreporter._numcollected
    passed = len([i for i in terminalreporter.stats.get('passed', []) if i.when == 'call'])
    failed = len([i for i in terminalreporter.stats.get('failed', []) if i.when == 'call'])
    error = len([i for i in terminalreporter.stats.get('error', []) if i.when == 'call'])
    skipped = len([i for i in terminalreporter.stats.get('skipped', []) if i.when != 'teardown'])
    success_rate = '%.2f' % (passed / total * 100)
    duration = time.time() - terminalreporter._sessionstarttime

    content = f"""
            ### ✨测试执行结果✨
            - <font color="#444444">项目名称：{sd.job_name}</font>
            - <font color="#444444">用例总数：{total}</font>
            - <font color="#66FF66">成功数：{passed}</font>
            - <font color="#FF5511">失败数：{failed}</font>
            - <font color="#0000FF">跳过数：{skipped}</font>
            - <font color="#FF0000">错误数：{error}</font>
            - <font color="#444444">成功率：▓▓▓▓▓▓▓▓▓▓▓ {success_rate} %</font>
            - <font color="#444444">执行时间：{round(duration, 2)} s</font>
                """

    sd.push_message(content)































































